# -*- coding: utf-8 -*-
import codecs
import random
from pytagcloud import create_tag_image, create_html_data, make_tags, \
    LAYOUT_HORIZONTAL, LAYOUTS
from pytagcloud.colors import COLOR_SCHEMES
from pytagcloud.lang.counter import get_tag_counts

wd = {}

fp=codecs.open(".\sort.txt", "r",'utf-8');

alllines=fp.readlines();

fp.close();

for eachline in alllines:
    line = eachline.split(':')
    wd[line[0]] =  int(float(line[1][:-11])*10000)
    print('%s%s'%(line[0],wd[line[0]]));


from operator import itemgetter
swd = sorted(wd.items(), key=itemgetter(1), reverse=True)
tags = make_tags(swd,minsize = 20, maxsize = 200,colors=random.choice(list(COLOR_SCHEMES.values())))
create_tag_image(tags, 'keyword_tag_cloud4.png', background=(34, 34, 34, 255),
size=(1200, 1000),layout=LAYOUT_HORIZONTAL,
fontname="SimHei")